package MultiNetworkingBase;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

public class SimpleUnit implements Drawable{
	//These are the things that the graphics manager needs to know to draw, and things the unit manager needs to know for logic
	public UnitType unitType;
	public int unitAllegiance; //player number of the owner of these units
	public double xPos;
	public double yPos;
	public double maxHP;
	public double curHP;
	public double xSpeed;
	public double ySpeed;
	//public double morale;
	public boolean isDead;
	public int move;
	public int uid; //unit ID
	public static int maxUID = 0;
	public boolean isAttacking;
	private final double WIDTH = 16;
	private final double HEIGHT = 16;
	
	public SimpleUnit(){}; //Empty constructor is necessary to be able to pass this across the network
	public SimpleUnit(UnitType uType, double x, double y){
		unitType = uType;
		xPos = x;
		yPos = y;
		maxHP = getUnitMaxHP(uType);
		curHP = maxHP;
		xSpeed = 0;
		ySpeed = 0;
		uid = maxUID;
		maxUID++;
		isAttacking = false;
		isDead = false;
		move = 1;
	}

	//TODO: move this to unit manager, just here temporarily, later coming from classes
	private double getUnitMaxHP(UnitType uType) {
		switch (uType){
		case lion:
			return 50;
		case gazelle:
			return 20;
		default:
			return 5;
		}
	}
	
	public Texture getTexture() {
		//TODO: Handle passing the animation stuff to TextureHolder to get the right texture
		return TextureHolder.tex;
	}
	
	public double getX() {
		return xPos;
	}
	public double getY() {
		return yPos;
	}
	public double getZ() {
		return (double)uid*-.0001;
	}
	public double getWidth() {
		return WIDTH;
	}
	public double getHeight() {
		return HEIGHT;
	}
	
	public void modify(SimpleUnit other) {
		unitType = other.unitType;
		unitAllegiance = other.unitAllegiance; 
		xPos = other.xPos;
		yPos = other.yPos;
		maxHP = other.maxHP;
		curHP = other.curHP;
		xSpeed = other.xSpeed;
		ySpeed = other.ySpeed;
		//morale = other.morale;
	}
	
	public void move(long delta) {
		//TODO: This is just here for testing purposes to keep the units on the screen
		if (xPos > 200)
			move = -1;
		if (xPos < 0)
			move = 1;
		xPos += xSpeed*delta*move;
		yPos += ySpeed*delta;
		
	}
}
